import { Component,Input, ElementRef, Renderer2, ViewChild  } from '@angular/core';
// import { NavController, NavParams } from 'ionic-angular';
// import { TopicInfo } from "../../models/quesinfo";
// import { Component,Input } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TopicInfo, RowInfo, DropdownInfo } from '../../models/quesinfo';
/**
 * Generated class for the QuestionTimePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
  selector: 'page-question-time',
  templateUrl: 'question-time.html',
})
export class QuestionTimePage {
  @Input() topic: TopicInfo;@Input() poneSet: Array<any>;
  @Input()
  topicIndex;
  topicIndexshow;

  @ViewChild('option1') option1: ElementRef;
  @ViewChild('select1') select1: ElementRef;

  @ViewChild('option2') option2: ElementRef;
  @ViewChild('select2') select2: ElementRef;

  @ViewChild('option3') option3: ElementRef;
  @ViewChild('select3') select3: ElementRef;

  @ViewChild('option4') option4: ElementRef;
  @ViewChild('select4') select4: ElementRef;

  @ViewChild('option5') option5: ElementRef;
  @ViewChild('select5') select5: ElementRef;

  @ViewChild('option6') option6: ElementRef;
  @ViewChild('select6') select6: ElementRef;

  constructor(public navCtrl: NavController, public navParams: NavParams, private elementRef: ElementRef, public renderer2: Renderer2) {
  }


  y;
  m;
  d;
  arrY = [];
  arrM = [];
  option;
  q;
  x;
  day;
  h;
  t;
  s;
  time10010 = [];

  hashour = true;
  hasminite=true;
  hassecond=true;
  hasyear=true;
  hasmonth=true;
  hasday=true;
  ngOnInit(): void {
    this.topicIndexshow=this.topicIndex+1;
    // this.topic["timeyear"] = "";
    // this.topic["timemonth"] = "";
    // this.topic["timeday"] = "";
    // this.topic["timehour"] = "";
    // this.topic["timeminite"] = "";
    // this.topic["timesecond"] = "";
    let hashour=false;

    // check_time:true
    // time:hour,minute,second
    for(var index = 0;index<this.topic.listRow.length;index++){
      // let FOptionContent = this.topic.listRow[index].FOptionContent;
      if(this.topic.listRow[2].FOptionContent = 'check_time:true'){
        if(this.topic.listRow[1].FOptionContent.indexOf("hour") != -1){

          this.hashour = false;
        }
        if(this.topic.listRow[1].FOptionContent.indexOf("minute") != -1){

          this.hasminite = false;

        }
        if(this.topic.listRow[1].FOptionContent.indexOf("second") != -1){

          this.hassecond = false;
        }


        if(this.topic.listRow[3].FOptionContent = 'check_date:true'){

          if(this.topic.listRow[0].FOptionContent.indexOf("year") != -1){

            this.hasyear = false;

          }
          if(this.topic.listRow[0].FOptionContent.indexOf("month") != -1){

            this.hasmonth = false;

          }
          if(this.topic.listRow[0].FOptionContent.indexOf("day") != -1){

            this.hasday = false;

          }
        }
      }

    }







    //++------------------------------------
    var sely = this.select1.nativeElement;


    for (this.y = 2000; this.y < 2100; this.y++) {

      this.option = this.renderer2.createElement('option');
      this.option.innerHTML = this.y;
      this.arrY.push(this.option);

      sely.append(this.option);
//       --------------------------------------------年
    }



    var selm = this.select2.nativeElement;

    for (this.m = 1; this.m < 13; this.m++) {

      this.q = this.renderer2.createElement('option');

      this.q.innerHTML = this.m ;

      this.arrM.push(this.q);

      selm.append(this.q);

    }
//---------------------------------------------------------------月
    var selh = this.select4.nativeElement;

    for (this.h = 0; this.h < 24; this.h++) {

      this.q = this.renderer2.createElement('option');

      this.q.innerHTML = this.h ;

      selh.append(this.q);

    }

//--------------------------------------------时

    var selt = this.select5.nativeElement;

    for (this.t = 0; this.t < 60; this.t++) {

      this.q = this.renderer2.createElement('option');

      this.q.innerHTML = this.t;

      selt.append(this.q);
    }
//-----------------------------------------------------分
    var sels = this.select6.nativeElement;

    for (this.s = 0; this.s < 60; this.s++) {

      this.q = this.renderer2.createElement('option');

      this.q.innerHTML = this.s ;

      sels.append(this.q);

    }
    this.timeedit();
    //
    // this.topic.timeyear="2018";
  }

  time(){

// for(var i = 0;i<this.arrY.length;i++){
//  if(this.arrY[i].selected == true){
//    var dataY =this.arrY[i].value;
//
//  }
// }
//
// for(var j = 0;j<this.arrM.length;j++){
//   if(this.arrM[j].selected == true){
//     var dataM = this.arrM[j].value;
//   }
// }
    var dataY=this.topic.timeyear;
    var dataM=this.topic.timemonth;
    var d;
    d = new Date(dataY,dataM,0);
    var day;
    day = d.getDate();
    //console.log(day)

    let num = [];

    var seld = this.select3.nativeElement;
    var optd = this.option3.nativeElement;

    if(seld.children ){

      seld.options.length=0;

    }

    for(var x = 1;x<=day;x++){
      this.day = this.renderer2.createElement('option');
      num.push(x);
      this.day.innerHTML = num[x-1];
      seld.append(this.day)

    }

    if(num.length!=0){
      this.topic.timeday= num[0].toString();
    }



  }
  timeedit(){

// for(var i = 0;i<this.arrY.length;i++){
//  if(this.arrY[i].selected == true){
//    var dataY =this.arrY[i].value;
//
//  }
// }
//
// for(var j = 0;j<this.arrM.length;j++){
//   if(this.arrM[j].selected == true){
//     var dataM = this.arrM[j].value;
//   }
// }

    var dataY=this.topic.timeyear;
    var dataM=this.topic.timemonth;
    if(dataY!=null&&dataM!=null&&dataY!=undefined&&dataM!=undefined&&dataY!=""&&dataM!="") {
      var d;
      d = new Date(dataY, dataM, 0);
      var day;
      day = d.getDate();
      //console.log(day)

      let num = [];

      var seld = this.select3.nativeElement;
      var optd = this.option3.nativeElement;

      if (seld.children) {

        seld.options.length = 0;

      }

      for (var x = 1; x <= day; x++) {
        this.day = this.renderer2.createElement('option');
        num.push(x);
        this.day.innerHTML = num[x - 1];
        seld.append(this.day)

      }

      // if (num.length != 0) {
      //   this.topic.timeday = num[0].toString();
      // }

    }
    // this.time10010.push(this.topic.timeyear,this.topic.timemonth,this.topic.timeday,this.topic.timehour,this.topic.timeminite,this.topic.timesecond)
    // console.log( this.time10010)
  }

}
